package de.hijacksoft.friendfinder;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBAdapter {

    public static final String DATABASE_NAME = " ";
    public static final String TABLE_NAME = " ";
    
    public static final int COLUMN_ID = 0;
    public static final int COLUMN_NAME = 0;
    public static final int COLUMN_POSITION = 0;
    
    public static final String KEY_ID = " ";
    public static final String KEY_NAME = " ";
    public static final String KEY_POINTS = " ";

    public static final int DATABASE_VERSION = 0;
    
    private SQLiteDatabase db;
    private SQLiteOpenHelper helper;
    
    private Context context;
    
    public DBAdapter(Context context){
        this.context = context;
        
        helper = new SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION){

            @Override
            public void onCreate(SQLiteDatabase db) {
                if(db == null) return;
                db.execSQL("CREATE TABLE " + TABLE_NAME + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_POINTS + " INTEGER );");
            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                if(db == null) return;
                db.execSQL("DROP TABLE " + TABLE_NAME + ";");
                onCreate(db);
            }
            
        };
    }
    
    public void open(){
        db = helper.getWritableDatabase();
    }
    
    public void close(){
        if(db == null) return;
        db.close();
    }
    
    public Cursor getAllItems(){
        return db.query(TABLE_NAME, null, null, null, null, null, null);
    }
}
